<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>CAPTCHA Adapters - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.captcha.adapters.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.captcha.adapters.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.captcha.operation.html">Captcha Operation</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.captcha.html">Zend_Captcha</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.cloud.html">SimpleCloud API: Zend_Cloud</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.captcha.adapters" class="section"><div class="info"><h1 class="title">CAPTCHA Adapters</h1></div>
    

    <p class="para">
        The following adapters are shipped with Zend Framework by default.
    </p>

    <div class="section" id="zend.captcha.adapters.word"><div class="info"><h1 class="title">Zend_Captcha_Word</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Captcha_Word</span> is an abstract adapter that serves as the base
            class for most other <acronym class="acronym">CAPTCHA</acronym> adapters. It provides mutators for
            specifying word length, session <acronym class="acronym">TTL</acronym>, the session namespace object
            to use, and the session namespace class to use for persistence if
            you do not wish to use <span class="classname">Zend_Session_Namespace</span>.
            <span class="classname">Zend_Captcha_Word</span> encapsulates validation logic.
        </p>

        <p class="para">
            By default, the word length is 8 characters, the session timeout is
            5 minutes, and <span class="classname">Zend_Session_Namespace</span> is used for persistence
            (using the namespace &quot;<span class="classname">Zend_Form_Captcha_&lt;captcha ID&gt;</span>&quot;).
        </p>

        <p class="para">
            In addition to the methods required by the
            <span class="classname">Zend_Captcha_Adapter</span> interface,
            <span class="classname">Zend_Captcha_Word</span> exposes the following methods:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">setWordLen($length)</span> and
                     <span class="methodname">getWordLen()</span> allow you to specify the length of the
                    generated &quot;word&quot; in characters, and to retrieve the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setTimeout($ttl)</span> and
                     <span class="methodname">getTimeout()</span> allow you to specify the time-to-live of
                    the session token, and to retrieve the current value. <var class="varname">$ttl</var>
                    should be specified in seconds.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setUseNumbers($numbers)</span> and
                     <span class="methodname">getUseNumbers()</span> allow you to specify if numbers will be
                    considered as possible characters for the random work or only letters would be
                    used.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setSessionClass($class)</span> and
                     <span class="methodname">getSessionClass()</span> allow you to specify an
                    alternate <span class="classname">Zend_Session_Namespace</span> implementation to
                    use to persist the <acronym class="acronym">CAPTCHA</acronym> token and to retrieve the
                    current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getId()</span> allows you to retrieve the current token
                    identifier.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getWord()</span> allows you to retrieve the generated
                    word to use with the <acronym class="acronym">CAPTCHA</acronym>. It will generate the word for
                    you if none has been generated yet.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setSession(Zend_Session_Namespace $session)</span> allows
                    you to specify a session object to use for persisting the
                    <acronym class="acronym">CAPTCHA</acronym> token.  <span class="methodname">getSession()</span> allows
                    you to retrieve the current session object.
                </p>
            </li>
        </ul>

        <p class="para">
            All word <acronym class="acronym">CAPTCHA</acronym>s allow you to pass an array of options to the
            constructor, or, alternately, pass them to
             <span class="methodname">setOptions()</span>. You can also pass a
            <span class="classname">Zend_Config</span> object to  <span class="methodname">setConfig()</span>. By
            default, the <em class="emphasis">wordLen</em>, <em class="emphasis">timeout</em>, and
            <em class="emphasis">sessionClass</em> keys may all be used. Each concrete
            implementation may define additional keys or utilize the options in
            other ways.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                <span class="classname">Zend_Captcha_Word</span> is an abstract class and may not be
                instantiated directly.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.captcha.adapters.dumb"><div class="info"><h1 class="title">Zend_Captcha_Dumb</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Captch_Dumb</span> adapter is mostly self-descriptive. It
            provides a random string that must be typed in reverse to validate. As such, it&#039;s
            not a good <acronym class="acronym">CAPTCHA</acronym> solution and should only be used for
            testing. It extends <span class="classname">Zend_Captcha_Word</span>.
        </p>
    </div>

    <div class="section" id="zend.captcha.adapters.figlet"><div class="info"><h1 class="title">Zend_Captcha_Figlet</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Captcha_Figlet</span> adapter utilizes <a href="zend.text.figlet.html" class="link"><span class="classname">Zend_Text_Figlet</span></a> to present
            a figlet to the user.
        </p>

        <p class="para">
            Options passed to the constructor will also be passed to the <a href="zend.text.figlet.html" class="link"><span class="classname">Zend_Text_Figlet</span></a> object.
            See the <a href="zend.text.figlet.html" class="link"><span class="classname">Zend_Text_Figlet</span></a>
            documentation for details on what configuration options are available.
        </p>
    </div>

    <div class="section" id="zend.captcha.adapters.image"><div class="info"><h1 class="title">Zend_Captcha_Image</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Captcha_Image</span> adapter takes the generated word and
            renders it as an image, performing various skewing permutations to make it
            difficult to automatically decipher. It
            requires the <a href="http://php.net/gd" class="link external">&raquo; GD extension</a>
            compiled with TrueType or Freetype support. Currently, the
            <span class="classname">Zend_Captcha_Image</span> adapter can only generate
            <acronym class="acronym">PNG</acronym> images.
        </p>

        <p class="para">
            <span class="classname">Zend_Captcha_Image</span> extends
            <span class="classname">Zend_Captcha_Word</span>, and additionally exposes the
            following methods:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">setExpiration($expiration)</span> and
                     <span class="methodname">getExpiration()</span> allow you to specify a maximum
                    lifetime the <acronym class="acronym">CAPTCHA</acronym> image may reside on the filesystem.
                    This is typically a longer than the session lifetime. Garbage
                    collection is run periodically each time the <acronym class="acronym">CAPTCHA</acronym> object
                    is invoked, deleting all images that have expired.
                    Expiration values should be specified in seconds.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setGcFreq($gcFreq)</span> and
                     <span class="methodname">getGcFreg()</span> allow you to specify how frequently garbage
                    collection should run. Garbage collection will run every
                    <strong class="command">1/$gcFreq</strong> calls. The default is 100.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setFont($font)</span> and  <span class="methodname">getFont()</span>
                    allow you to specify the font you will use. <var class="varname">$font</var>
                    should be a fully qualified path to the font file.
                    This value is required; the <acronym class="acronym">CAPTCHA</acronym> will throw an
                    exception during generation if the font file has not been specified.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setFontSize($fsize)</span> and
                     <span class="methodname">getFontSize()</span> allow you to specify the font size in
                    pixels for generating the <acronym class="acronym">CAPTCHA</acronym>. The default is 24px.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setHeight($height)</span> and
                     <span class="methodname">getHeight()</span> allow you to specify the height in pixels
                    of the generated <acronym class="acronym">CAPTCHA</acronym> image. The default is 50px.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setWidth($width)</span> and
                     <span class="methodname">getWidth()</span> allow you to specify the width in pixels of
                    the generated <acronym class="acronym">CAPTCHA</acronym> image. The default is 200px.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setImgDir($imgDir)</span> and
                     <span class="methodname">getImgDir()</span> allow you to specify the directory for
                    storing <acronym class="acronym">CAPTCHA</acronym> images. The default is
                    &quot;<var class="filename">./images/captcha/</var>&quot;, relative to the bootstrap script.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setImgUrl($imgUrl)</span> and
                     <span class="methodname">getImgUrl()</span> allow you to specify the relative path to
                    a <acronym class="acronym">CAPTCHA</acronym> image to use for <acronym class="acronym">HTML</acronym> markup.
                    The default is &quot;<var class="filename">/images/captcha/</var>&quot;.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setSuffix($suffix)</span> and
                     <span class="methodname">getSuffix()</span> allow you to specify the filename suffix
                    for the <acronym class="acronym">CAPTCHA</acronym> image. The default is
                    &quot;<var class="filename">.png</var>&quot;. Note: changing this value will not change the type
                    of the generated image.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setDotNoiseLevel($level)</span> and
                     <span class="methodname">getDotNoiseLevel()</span>, along with
                     <span class="methodname">setLineNoiseLevel($level)</span> and
                     <span class="methodname">getLineNoiseLevel()</span>,
                    allow you to control how much &quot;noise&quot; in the form of random dots and lines the
                    image would contain. Each unit of <var class="varname">$level</var> produces one random
                    dot or line. The default is 100 dots and 5 lines. The noise is added twice -
                    before and after the image distortion transformation.
                </p>
            </li>
        </ul>

        <p class="para">
            All of the above options may be passed to the
            constructor by simply removing the &#039;set&#039; method prefix and casting
            the initial letter to lowercase: &quot;suffix&quot;, &quot;height&quot;, &quot;imgUrl&quot;, etc.
        </p>
    </div>

    <div class="section" id="zend.captcha.adapters.recaptcha"><div class="info"><h1 class="title">Zend_Captcha_ReCaptcha</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Captcha_ReCaptcha</span> adapter uses <a href="zend.service.recaptcha.html" class="link">Zend_Service_ReCaptcha</a>
            to generate and validate <acronym class="acronym">CAPTCHA</acronym>s. It exposes the following
            methods:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">setPrivKey($key)</span> and
                     <span class="methodname">getPrivKey()</span> allow you to specify the private key to
                    use for the ReCaptcha service. This must be specified during construction,
                    although it may be overridden at any point.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setPubKey($key)</span> and
                     <span class="methodname">getPubKey()</span> allow you to specify the public key to use
                    with the ReCaptcha service. This must be specified during construction, although
                    it may be overridden at any point.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setService(Zend_Service_ReCaptcha $service)</span> and
                     <span class="methodname">getService()</span> allow you to set and get
                    the ReCaptcha service object.
                </p>
            </li>
            
            <li class="listitem">
                <p class="para">
                     <span class="methodname">isValid($value, $context = null)</span> validates the user&#039;s
                    input against the ReCaptcha service.  <var class="varname">$value</var> is an array with the following
                    keys:  
                    <ul class="itemizedlist">
                        <li class="listitem">
                            <p class="para">
                                <var class="varname">recaptcha_challenge_field</var> - Value of the ReCaptcha widget&#039;s 
                                challenge field (hidden)
                            </p>
                        </li>
                        <li class="listitem">                        
                            <p class="para">
                                <var class="varname">recaptcha_response_field</var> - Value of the ReCaptcha widget&#039;s
                                user input field
                            </p>
                        </li>
                    </ul>
                </p>
            </li>
        </ul>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.captcha.operation.html">Captcha Operation</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.captcha.html">Zend_Captcha</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.cloud.html">SimpleCloud API: Zend_Cloud</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.captcha.html">Zend_Captcha</a></li>
  <li><a href="zend.captcha.introduction.html">Introduction</a></li>
  <li><a href="zend.captcha.operation.html">Captcha Operation</a></li>
  <li class="active"><a href="zend.captcha.adapters.html">CAPTCHA Adapters</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>